package com.ctrip.cap.device;

import com.ctrip.cap.common.exception.CapException;
import com.ctrip.cap.device.android.impl.DefaultDeviceStore;
import com.ctrip.cap.device.ios.impl.IPhoneDeviceStore;

/**
 * static is bad
 * 
 * @author ltyao
 *
 */
public class DeviceStoreFactory {

	private static DeviceStore<? extends Device> deviceStore;

	public static synchronized DeviceStore<? extends Device> create(
			MobilePlatformType deviceType) {
		// if (deviceStore != null) {
		// return deviceStore;
		// }

		switch (deviceType) {
		case Android:
			deviceStore = DefaultDeviceStore.getInstance();
			break;
		case iOS:
			deviceStore = IPhoneDeviceStore.getInstance();
			break;
		default:
			break;
		}

		return deviceStore;
	}

	public static DeviceStore<? extends Device> getDeviceStore() {
		if (deviceStore == null) {
			throw new CapException("device store was not initialized ");
		}
		return deviceStore;
	}

	public enum MobilePlatformType {
		Android, iOS;
	}

}
